﻿package mortal.game.view.battlefield
{
    import Message.Public.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class BattlefieldIcon extends ActionBaseIcon
    {
        private static var _instance:BattlefieldIcon;

        public function BattlefieldIcon()
        {
            super(ResFileConst.BattlefieldIcon);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.updateTimeTip();
            return;
        }// end function

        override protected function clickHandler(event:MouseEvent) : void
        {
            var _loc_3:Date = null;
            var _loc_4:Date = null;
            var _loc_5:int = 0;
            var _loc_2:* = Cache.instance.battlefieldCache.battlefieldOpen;
            if (_loc_2)
            {
                _loc_3 = _loc_2.openDt;
                _loc_4 = _loc_2.endDt;
                _loc_5 = (_loc_3.time - ClockManager.instance.nowDate.time) / 1000;
                if (_loc_5 > 0)
                {
                    MsgManager.showRollTipsMsg(Language.getString(11305));
                }
                else
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.BattlefieldEnterWindowShow));
                }
            }
            return;
        }// end function

        protected function updateTimeTip() : void
        {
            var _loc_2:Date = null;
            var _loc_3:Date = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_1:* = Cache.instance.battlefieldCache.battlefieldOpen;
            if (_loc_1)
            {
                _loc_2 = _loc_1.openDt;
                _loc_3 = _loc_1.endDt;
                _loc_4 = (_loc_2.time - ClockManager.instance.nowDate.time) / 1000;
                if (_loc_4 > 0)
                {
                    this.setLeftTimeAndState(_loc_4, 1);
                }
                else
                {
                    _loc_5 = (_loc_3.time - ClockManager.instance.nowDate.time) / 1000;
                    if (_loc_5 > 0)
                    {
                        this.setLeftTimeAndState(_loc_5, 2);
                    }
                }
            }
            return;
        }// end function

        override protected function timeOutCaller() : void
        {
            this.updateTimeTip();
            return;
        }// end function

        public static function get instance() : BattlefieldIcon
        {
            if (!_instance)
            {
                _instance = new BattlefieldIcon;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
